Post

Replies

Boosts

Views

Activity

Reply to Widget showsWidgetContainerBackground fallback
@t9mike thanks, how do you compile your WidgetEntryView because .showsWidgetContainerBackground only available in iOS 17? and i have see those Xcode runtime error, so i tried a new approach but it couldn't work neither: final class WidgetEnvironmentContext { static let shared = WidgetEnvironmentContext() var showsWidgetContainerBackground: Bool = true } @available(iOS 17.0, *) struct WidgetEnvironmentReader: View { @Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground: Bool var body: some View { WidgetEnvironmentContext.shared.showsWidgetContainerBackground = showsWidgetContainerBackground return Color.clear } } struct ExampleView: View { var body: some View { ZStack { if #available(iOS 17, *) { WidgetEnvironmentReader() } Text("Shows Background: \(WidgetEnvironmentContext.shared.showsWidgetContainerBackground ? "YES" : "NO")") } } } showsWidgetContainerBackground variable is randomly wrong in this way, i am so confuse now, i think i just use separate view in my code struct WidgetView: View { var body: some View { if #available(iOS 17, *) { HeaderView() } else { FallbackHeaderView() } ... } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’23
Reply to Widget showsWidgetContainerBackground fallback
Ok, after a little digging(actually a lot...), i think i finally have a solution, just in case anyone dealing the some issue: // First we create a fallback variable environment struct WidgetEnvShowsContainerBackgroundKey: EnvironmentKey { static let defaultValue: Bool = true } extension EnvironmentValues { var widgetEnvShowsContainerBackground: Bool { set { self[WidgetEnvShowsContainerBackgroundKey.self] = newValue } get { self[WidgetEnvShowsContainerBackgroundKey.self] } } } extension View { func envShowsContainerBackground(_ value: Bool) -> some View { environment(\.widgetEnvShowsContainerBackground, value) } } // Magic happens here struct WidgetEnvironmentReader<Content: View>: View { var content: () -> Content init(@ViewBuilder content: @escaping () -> Content) { self.content = content } var body: some View { if #available(iOS 17.0, *) { WidgetEnvironmentViewBuilder(content: content) } else { content() } } } extension WidgetEnvironmentReader { @available(iOS 17.0, *) struct WidgetEnvironmentViewBuilder<C: View>: View { @Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground var content: () -> C init(@ViewBuilder content: @escaping () -> C) { self.content = content } var body: some View { content() .envShowsContainerBackground(showsWidgetContainerBackground) } } } // Now we are free to use .showsWidgetContainerBackground in the older os version @available(iOS 14.0, *) struct WidgetView: View { @Environment(\.widgetEnvShowsContainerBackground) var widgetEnvShowsContainerBackground: Bool var body: some View { Text("Background: \(widgetEnvShowsContainerBackground ? "YES" : "No"), \(Date(), style: .relative)") } } @available(iOS 14.0, *) struct WidgetEntryView: View { let entry: Entry var body: some View { WidgetEnvironmentReader { WidgetView() } .makeContainerBackground() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’23
Reply to Xcode crash when upload to app connect
Same problem here, Xcode 15 beta and Xcode 15 RC, crash when trying upload app to notarize. ------------------------------------- Translated Report (Full Report Below) ------------------------------------- Process: Xcode [7242] Path: /Applications/Xcode.app/Contents/MacOS/Xcode Identifier: com.apple.dt.Xcode Version: 15.0 (22265) Build Info: IDEApplication-22265000000000000~3 (15A240d) Code Type: ARM-64 (Native) Parent Process: launchd [1] User ID: 501 Date/Time: 2023-09-13 11:12:33.6172 +0800 OS Version: macOS 14.0 (23A339) Report Version: 12 Anonymous UUID: 11BE4F5F-3C85-690B-0E16-188F1FDB7B73 Time Awake Since Boot: 2300 seconds System Integrity Protection: enabled Crashed Thread: 0 Dispatch queue: archive info plist lock Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: Namespace SIGNAL, Code 6 Abort trap: 6 Terminating Process: Xcode [7242] Application Specific Information: com.apple.main-thread abort() called Application Specific Signatures: (string) != nil Thread 0 Crashed:: Dispatch queue: archive info plist lock 0 libsystem_kernel.dylib 0x190f6b11c __pthread_kill + 8 1 libsystem_pthread.dylib 0x190fa2cc0 pthread_kill + 288 2 libsystem_c.dylib 0x190eb2a50 abort + 180 3 IDEKit 0x107a38d58 +[IDEAssertionHandler _handleAssertionWithLogString:assertionSignature:assertionReason:extraBacktrace:] + 972 4 IDEKit 0x107a39198 -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:assertionSignature:messageFormat:arguments:] + 872 5 DVTFoundation 0x103f299a8 _DVTAssertionHandler + 424 6 DVTFoundation 0x103f29b28 _DVTAssertionFailureHandler + 196 7 DVTFoundation 0x103dec3d4 +[DVTFilePath _filePathForParent:pathString:] + 360 8 DVTFoundation 0x103decb20 -[DVTFilePath filePathForRelativePathString:] + 48 9 IDEFoundation 0x10960286c -[IDEArchive _embedPackageFromDistributionRecord:error:] + 312 10 IDEFoundation 0x109602ea4 __36-[IDEArchive addDistribution:error:]_block_invoke + 56 11 libdispatch.dylib 0x190df5910 _dispatch_client_callout + 20 12 libdispatch.dylib 0x190e04cc4 _dispatch_lane_barrier_sync_invoke_and_complete + 56 13 DVTFoundation 0x103f70014 DVTDispatchBarrierSync + 148 14 DVTFoundation 0x103f4c2b4 -[DVTDispatchLock performLockedBlock:] + 60 15 IDEFoundation 0x109602d30 -[IDEArchive addDistribution:error:] + 200 16 IDEFoundation 0x1092a82f0 __35-[IDEDistributionUploadStep upload]_block_invoke.115 + 116 17 DVTFoundation 0x103f6f330 __DVT_CALLING_CLIENT_BLOCK__ + 16 18 DVTFoundation 0x103f6fb08 __DVTSyncPerformBlock_block_invoke + 68 19 CoreFoundation 0x19107f8c0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28 20 CoreFoundation 0x19107f7d4 __CFRunLoopDoBlocks + 356 21 CoreFoundation 0x19107ec68 __CFRunLoopRun + 2440 22 CoreFoundation 0x19107dc2c CFRunLoopRunSpecific + 608 23 HIToolbox 0x19b5d6448 RunCurrentEventLoopInMode + 292 24 HIToolbox 0x19b5d6284 ReceiveNextEventCommon + 648 25 HIToolbox 0x19b5d5fdc _BlockUntilNextEventMatchingListInModeWithFilter + 76 26 AppKit 0x1948590ec _DPSNextEvent + 660 27 AppKit 0x19502cc2c -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 716 28 DVTKit 0x102de0a9c -[DVTApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 300 29 AppKit 0x19484c598 -[NSApplication run] + 476 30 DVTKit 0x102ddfcbc -[DVTApplication run] + 60 31 AppKit 0x194823864 NSApplicationMain + 880 32 dyld 0x190c29058 start + 2224 Model: iMac21,2, BootROM 10151.1.1, proc 8:4:4 processors, 16 GB, SMC Graphics: Apple M1, Apple M1, Built-In Display: iMac, Retina 4.5K (4480 x 2520), Main, MirrorOff, Online Memory Module: LPDDR4, Hynix AirPort: spairport_wireless_card_type_wifi (0x14E4, 0x4378), wl0: Jul 8 2023 17:42:24 version 18.20.438.0.7.8.162 FWID 01-045ed435 AirPort: Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports Network Service: Ethernet Adapter (en4), Ethernet, en4 Network Service: Wi-Fi, AirPort, en1 USB Device: USB31Bus USB Device: USB31Bus USB Device: USB3.1 Hub USB Device: PSSD T7 Shield USB Device: USB2.0 Hub USB Device: Magic Trackpad Thunderbolt Bus: iMac, Apple Inc. Thunderbolt Bus: iMac, Apple Inc.
Topic: App & System Services SubTopic: Core OS Tags:
Sep ’23